﻿Imports System, System.Collections.Generic, System.Linq,
System.Runtime.InteropServices, System.Windows
Imports System.Windows.Interop
Imports System.Windows.Media
Imports Microsoft.Windows.Shell

Public Class MinimalistWindow : Inherits Windows.Window

    ''' <summary>
    ''' Default New.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()
        MyClass.New("MinimalistWindow by Ken", New Thickness(4), New Thickness(0), New CornerRadius(2), 20)
    End Sub

    ''' <summary>
    ''' Extended New.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New(ByVal _TITLE As String,
                   ByVal _FRMRSZBRDRTKNS As Thickness,
                   ByVal _GLSFRMTKNS As Thickness,
                   ByVal _CRNRRADIUS As CornerRadius,
                   ByVal _TTLBRHEIGHT As Double)

        Background = Brushes.LightGray
        Title = _TITLE

        If Environment.OSVersion.Version.Major < 6 Then
            WindowStyle = Windows.WindowStyle.None
            AllowsTransparency = True

            'Throw New Exception("Versione del Sistema Operativo non compatibile." & vbCrLf & " MinimalistWindow richiede almeno Windows Vista." & vbCrLf & vbCrLf & _
            '                    "The current OS Version is Not Compatible with MinimalistWindow." & vbCrLf & "OS Vista (or Newer) Needed.")
            Return
        End If
        'Questa porzione della finestra ha senso solo se siamo in un sistema operativo Vista ( o superiore )

        Dim wc As New Microsoft.Windows.Shell.WindowChrome
        wc.ResizeBorderThickness = _FRMRSZBRDRTKNS
        SetValue(FrameProperty, _FRMRSZBRDRTKNS)
        'L'ombra della finestra viene creata a partire dallo spessore della finestra.
        wc.GlassFrameThickness = _GLSFRMTKNS
        wc.CornerRadius = _CRNRRADIUS
        wc.CaptionHeight = _TTLBRHEIGHT
        SetValue(BannerHeightProperty, _TTLBRHEIGHT)
        WindowChrome.SetWindowChrome(Me, wc)



    End Sub

    ' ''' <summary>
    ' ''' Dispone|Rimuove l'ombra alla finestra.
    ' ''' </summary>
    ' ''' <returns></returns>
    ' ''' <remarks>Restituisce Vero se DOPO l'applicazione della funzione l'ombra è visibile, Falso nel caso contrario.</remarks>
    'Public Function ToggleShadow() As Boolean
    '    WindowChrome.GetWindowChrome(Me).GlassFrameThickness = New Thickness(0, 0, 0, _SHADOWVISIBLE)
    '    _SHADOWVISIBLE = Not _SHADOWVISIBLE
    '    Return _SHADOWVISIBLE       
    'End Function

    Public ReadOnly Property Frame As Thickness
        Get
            Return GetValue(FrameProperty)
        End Get
    End Property

    Public Shared ReadOnly FrameProperty As DependencyProperty = _
                           DependencyProperty.Register("Frame", _
                           GetType(Thickness), GetType(MinimalistWindow), _
                           New FrameworkPropertyMetadata(Nothing))

    Public Property CornerRadius As CornerRadius
        Get
            Return GetValue(CornerRadiusProperty)
        End Get

        Set(ByVal value As CornerRadius)
            SetValue(CornerRadiusProperty, value)
        End Set
    End Property

    Public Shared ReadOnly CornerRadiusProperty As DependencyProperty = _
                           DependencyProperty.Register("CornerRadius", _
                           GetType(CornerRadius), GetType(MinimalistWindow), _
                           New FrameworkPropertyMetadata(Nothing))


    Public ReadOnly Property BannerHeight As Double
        Get
            Return GetValue(BannerHeightProperty)
        End Get

    End Property

    Public Shared ReadOnly BannerHeightProperty As DependencyProperty = _
                           DependencyProperty.Register("BannerHeight", _
                           GetType(Double), GetType(MinimalistWindow), _
                           New FrameworkPropertyMetadata(Nothing))



    ''' <summary>
    ''' Rende un elemento della finestra sensibile all'input.
    ''' </summary>
    ''' <param name="element">L'elemento da rendere sensibile.</param>
    ''' <remarks></remarks>
    Public Sub EnableElement(ByRef element As IInputElement)
        WindowChrome.SetIsHitTestVisibleInChrome(element, True)
    End Sub

    ''' <summary>
    ''' Rende un elemento della finestra insensibile all'input.
    ''' </summary>
    ''' <param name="element">L'elemento da rendere insensibile.</param>
    ''' <remarks></remarks>
    Public Sub DisableElement(ByRef element As IInputElement)
        WindowChrome.SetIsHitTestVisibleInChrome(element, False)
    End Sub

End Class
